package model

import (
	"encoding/json"
	"time"
)

type GroupsMessages struct {
	Id       int64    `json:"id" xorm:"not null pk autoincr BIGINT"`
	Mid      int64    `json:"mid" xorm:"BIGINT notnull comment('消息id') index"`
	AppsId   uint      `json:"apps_id" xorm:"INT notnull comment('app id') index"`
	From     int64    `json:"from" xorm:"BIGINT notnull comment('拨号用户id') index"`
	To       int64    `json:"to" xorm:"BIGINT notnull comment('目标id') index"`
	Text     string    `json:"text" xorm:"TEXT comment('消息内容')"`
	TextType int       `json:"text_type" xorm:"TINYINT notnull default 1 comment('消息类型 1:文字 2:图片 3:语音')"`
	Status   int       `json:"status" xorm:"TINYINT notnull default 1 comment('消息状态 3:删除 2:撤回 1:正常')"`
	Created  time.Time `json:"created,omitempty" xorm:"'created' created notnull TIMESTAMP index"`
	Updated  time.Time `json:"updated,omitempty" xorm:"'updated' updated TIMESTAMP"`
}

const (
	_ int = iota
	GroupsMessages_Type_Text
	GroupsMessages_Type_Image
	GroupsMessages_Type_Voice
	GroupsMessages_Type_Post
)
const (
	_ int = iota
	GroupsMessages_Status_Normal
	GroupsMessages_Status_Recall
	GroupsMessages_Status_Delete
)

func (m GroupsMessages) TableName() string {
	return "groups_messages"
}

func (m *GroupsMessages) Marshal() ([]byte, error) {
	return json.Marshal(m)
}

func (m *GroupsMessages) Unmarshal(b []byte) error {
	return json.Unmarshal(b, m)
}
